package com.neusoft.SPNursingHome.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.SPNursingHome.po.CheckOutRecord;
import com.neusoft.SPNursingHome.po.OutingRecord;
import com.neusoft.SPNursingHome.po.ResponseBean;
import com.neusoft.SPNursingHome.service.OutingRecordService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("/api/outing")
public class OutingRecordController {

    @Resource
    private OutingRecordService outingRecordService;

    @PostMapping("/list")
    public ResponseBean<IPage<OutingRecord>> list(
            @RequestParam(defaultValue = "1") long pageNum,
            @RequestParam(defaultValue = "10") long pageSize,
            @RequestBody Map<String, Object> query) {
        return outingRecordService.listRequests(pageNum, pageSize, query);
    }

    @PostMapping("/apply")
    public ResponseBean<Void> apply(@RequestBody OutingRecord request) {
        return outingRecordService.applyForOuting(request);
    }

    @PutMapping("/audit")
    public ResponseBean<Void> audit(
            @RequestBody OutingRecord auditInfo) {
        return outingRecordService.auditRequest(auditInfo);
    }

    @PutMapping("/{outingId}/return")
    public ResponseBean<Void> recordReturn(
            @PathVariable Integer outingId,
            @RequestBody Map<String, Date> payload) {

        Date returnTime = payload.get("returnTime");
        return outingRecordService.recordClientReturn(outingId, returnTime);
    }
}
